home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_geomview.idb / usr / freeware / lib / geomview / doc / OOGL.m.doc.z / OOGL.m.doc
Encoding:
Text File  |  1999-01-26  |  16.9 KB  |  412 lines

  1.  
  2. NOTE: This file is autogenerated from the Geomview manual.
  3.   For references to things not in this file, see the manual.
  4.   The manual is distributed in the "doc" subdirectory.
  5.  
  6.  
  7. Mathematica Graphics in Geomview or RenderMan
  8. *********************************************
  9.  
  10. Geomview comes with some Mathematica packages that let you use use
  11. Geomview to display Mathematica graphics.  Mathematica is a commercial
  12. mathematical software system available from Wolfram Research, Inc.
  13.  
  14. There are two ways to do this.
  15.   1. Use Mathematica to write a graphics object to a file in OOGL format
  16.      or in RIB format.
  17.   2. Use Geomview as the default display for all 3D graphics output in
  18.      Mathematica.
  19. You can also use these packages to save Mathematica graphics in
  20. RenderMan (RIB) format.
  21.  
  22. Since the format of Mathematica graphics objects is different from the
  23. OOGL formats, both of these methods involve translating Mathematica
  24. graphics to OOGL format.  Geomview is distributed with a Mathematica
  25. package which does this translation.  Before doing either of the
  26. above you must install this package.
  27.  
  28. Using Mathematica to generate OOGL files
  29. ========================================
  30.  
  31. The package `OOGL.m' allows Mathematica to write graphics objects in
  32. OOGL format.  To use it, give the command `<< OOGL.m' to Mathematica to
  33. load the package.  The `WriteOOGL[FILE,GRAPHICS]' command writes an OOGL
  34. description of the 3D graphics object GRAPHICS to the file named FILE.
  35.  
  36. This package also provides the `Geomview' command which sends a
  37. 3D graphics object to Geomview.  The first time you use this command
  38. it starts up a copy of Geomview.  Later calls send the graphics to the
  39. same Geomview.  There are two ways to use the `Geomview' command.
  40.  
  41. `Geomview[GRAPHICS]'
  42.      Sends the 3D graphics object GRAPHICS to Geomview as a geom named
  43.      `Mathematica'.  Subsequent usage of `Geomview[GRAPHICS]'
  44.      replaces the `Mathematica' object in Geomview with the new
  45.      GRAPHICS.
  46.  
  47. ``Geomview[NAME,GRAPHICS]''
  48.      Sends the 3D graphics object GRAPHICS to Geomview as a geom named
  49.      NAME.  You can use multiple calls of this form with different
  50.      names to cause Geomview to display several Mathematica objects at once
  51.      and allow independent control over them.
  52.      % math
  53.      Mathematica 2.0 for SGI Iris
  54.      Copyright 1988-91 Wolfram Research, Inc.
  55.       -- GL graphics initialized --
  56.  
  57.      In[1] := <<OOGL.m
  58.  
  59.      In[2] := Plot3D[Sin[x + Sin[y]], {x,-2,2},{y,-2,2}]
  60.  
  61.      Out[2] := -Graphics3D-
  62. This displays graphics in the usual Mathematica way here.
  63.      In[3] := WriteOOGL["math.oogl", %2]
  64.  
  65.      Out[3] := -Graphics3D-
  66. This displays nothing new but writes the file `math.oogl'.
  67. You can now load that file into Geomview on any computer.  Alternately,
  68. you can use the `Geomview' command to start up a copy of Geomview
  69. from within Mathematica.
  70.      In[5] := Geomview[%2]
  71.  
  72.      Out[5] := -Graphics3D-
  73.  
  74.  
  75.  
  76. Using Geomview as Mathematica's Default 3D Display
  77. ==================================================
  78.  
  79. The package `Geomview.m' arranges for Geomview to be the
  80. default display program for 3D graphics in Mathematica.  To
  81. load it, give the command `<< Geomview.m' to Mathematica.
  82. Thereafter, whenever you display 3D graphics with `Plot3D'
  83. or `Show', Mathematica will send the graphics to Geomview.
  84.  
  85. Loading `Geomview.m' implicitly loads `OOGL.m' as well, so you
  86. can use the `Geomview' and `WriteOOGL' as described above
  87. after loading `Geomview.m'.  You do not have to separately load
  88. `OOGL.m'.
  89.      % math
  90.      Mathematica 2.0 for SGI Iris
  91.      Copyright 1988-91 Wolfram Research, Inc.
  92.       -- GL graphics initialized --
  93.  
  94.      In[1] := <<Geomview.m
  95.  
  96.      In[2] := Plot3D[x^2 + y^2, {x, -2, 2}, {y, -2, 2}]
  97.  
  98.      Out[2] := -SurfaceGraphics-
  99. This invokes geomivew and loads the graphics object into it.
  100.      In[3] := Plot3D[{x*y + 6, RGBColor[0,x,y]}, {x,0,1}, {y,0,1}]
  101.  
  102.      Out[3] := -SurfaceGraphics-
  103. This replaces the previous Geomview object by the new object. 
  104.      In[4] := Geomview[{%2,%3}]
  105.  
  106.      Out[4] := {-SurfaceGraphics-, -SurfaceGraphics-}
  107. This displays both objects at once.  You also can have more than one
  108. Mathematica object at a time on display in Geomview, and have separate
  109. control over them, by using the `Geomview' command with a name,
  110. *Note OOGL.m::.
  111.      In[5] := Graphics3D[ {RGBColor[1,0,0], Line[{ {2,2,2},{1,1,1} }] }]
  112.  
  113.      Out[5] := -Graphics3D-
  114.  
  115.      In[6] := Geomview["myline", %5]
  116. This addes the `Line' specified in `In[5]' to the existing
  117. Geomview display.  It can be controlled independently of the
  118. "Mathematica" object, which is currently the list of two plots.
  119.      In[7] := <<GL.m
  120. If you're on an SGI, loading `GL.m' returns Mathematica to its
  121. usual 3D graphics display.  To do this on a NeXT you should load
  122. `PSDirect.m' if you are using Mathematica in a notebook, or
  123. `NeXT.m' if you invoked Mathematica from a shell.  The following
  124. plot will appear in a normal static Mathematica window.
  125.      In[8] := ParametricPlot3D[{Sin[x],Sin[y],Sin[x]*Cos[y]}, {x,0,Pi},{y,0,Pi}]
  126.  
  127.      Out[8] := -Graphics3D-
  128. We can return to Geomview graphics at any time by reloading `Geomview.m'.
  129.      In[9] := <<Geomview.m
  130.  
  131.      In[10] := Show[%8]
  132.  
  133.      Out[10] := -Graphics3D-
  134.  
  135.      In[11] := ParametricPlot3D[
  136.             {(2*(Cos[u] + u*Sin[u])*Sin[v])/(1 + u^2*Sin[v]^2),
  137.             (2*(Sin[u] - u*Cos[u])*Sin[v])/(1 + u^2*Sin[v]^2),
  138.             Log[Tan[v/2]] + (2*Cos[v])/(1 + u^2*Sin[v]^2)},
  139.            {u,-4,4},{v,.01,Pi-.01}]
  140.  
  141.      Out[11] := -Graphics3D-
  142. This last plot is Kuen's surface, a surface of constant negative
  143. curvature.  Parametrization from Alfred Gray's *Modern Differential
  144. Geometry of Curves and Surfaces* textbook.
  145.  
  146.  
  147. Using Mathematica to generate RenderMan files
  148. =============================================
  149.  
  150. In addition to the `WriteOOGL' and `Geomview' commands
  151. described above, the package `OOGL.m' also defines the command
  152. `WriteRIB' which writes a 3D graphics object to a RenderMan RIB
  153. file:  `WriteRIB[FILE, GRAPHICS]' writes GRAPHICS
  154. to file FILE.  RenderMan is a commercial rendering system available
  155. from Pixar, Inc., which can produce extremely high quality images.
  156.      In[1] := <<OOGL.m
  157.  
  158.      In[2] := <<Graphics/Polyhedra.m
  159.  
  160.      In[3] := Graphics3D[Cube[]]
  161.  
  162.      Out[3] := -Graphics3D-
  163.  
  164.      In[4] := WriteRIB["cube.rib", %3]
  165.  
  166.      Out[4] := -Graphics3D- This generates the file `math.rib'.  This is
  167. a ready-to-render RIB file of the given geometry, using a default camera
  168. position, lighting, and the "plastic" shader. In a shell window, type
  169. `render cube.rib' to generate the image file `mma.tiff'. Of course, you
  170. need to have RenderMan installed for this to work. A shortcut to render
  171. from inside Mathematica is `WriteRIB["!render", foo]'.
  172.  
  173. `WriteRIB' works by first converting the Mathematica graphics
  174. object to OOGL format using `WriteOOGL' and then calls an external
  175. program `oogl2rib' to convert OOGL to RIB format.  The
  176. oogl2rib program takes several options which you can specify in a
  177. string as an optional third argument to `WriteRIB'.  The default
  178. option string is `" -n mma.tiff "', which indicates that the RIB
  179. file should generate a rendered TIFF file named `mma.tiff'.  A
  180. particularly useful option is `-g', which tells oogl2rib to
  181. convert only the geometry into a RIB fragment. You can insert that
  182. fragment into a full RIB file of your own making with camera positions
  183. and shaders of your choice, to harness the full power of RenderMan.
  184.  
  185. The full usage of oogl2rib is:
  186.      oogl2rib [-n NAME] [-B R,G,B] [-w WIDTH] [-h HEIGHT] [-fgb] [INFILE] [OUTFILE]
  187. By default it reads from stdin and writes to stdout.
  188. Either INFILE or OUTFILE may be `-', which means
  189. use stdin/stdout.  The options are:
  190.  
  191. `-n NAME'
  192.      Use NAME for the name of the rendered TIFF file (default
  193.      "geom.tiff") or framebuffer window (default "geom.rib").
  194.  
  195. `-B R,G,B'
  196.      Use background color (R,G,B).  Each component ranges
  197.      from 0 to 1. Default: none.
  198.  
  199. `-w WIDTH -h HEIGHT'
  200.      Rendered frame will be WIDTH by HEIGHT pixels.
  201.  
  202. `-f'
  203.      RIB file renders to on-screen framebuffer instead of TIFF file.
  204.  
  205. `-g'
  206.      Output only the geometry in RIB format.
  207.  
  208. `-b'
  209.      Output only a Quick Renderman clip object.  Ignores -nBwhf.
  210.  
  211.  
  212.  
  213.  
  214. Using Geomview and Mathematica on Different Computers
  215. =====================================================
  216.  
  217. It is possible to use Geomview to display graphics generated by
  218. Mathematica running on a different computer.  If each computer is either
  219. an SGI or a NeXT and they are networked together, you can tell
  220. Mathematica to use a remote host for Geomview graphics.  If you want to
  221. use Mathematica on a computer that is not networked with your Geomview
  222. computer, or on any kind of computer other than an SGI or a NeXT (for
  223. example a PC or a Mac), you can write out *chunk* files in
  224. Mathematica which you transfer to the Geomview computer and then
  225. translate to OOGL format.
  226.  
  227. Using a Networked Geomview Host
  228. -------------------------------
  229.  
  230. The `Geomview' command looks at the `DISPLAY' or
  231. `REMOTEHOST' environment variables to try to determine if you are
  232. logged in from another computer.  If either of these indicates that you
  233. are, `Geomview' will attempt to run Geomview on that
  234. computer.  In order for this to work, your network must be configured
  235. such that the Mathematica computer can successfully `rsh' to the
  236. Geomview computer without giving a password.
  237.  
  238. You can also explicitly set the `DisplayHost' option to the
  239. `Geomview' command to a string which is the desired hostname, for
  240. example:
  241.      In[1] := << OOGL.m
  242.  
  243.      In[2] := Plot3D[Sin[x + Sin[y]], {x,-2,2},{y,-2,2}]
  244.  
  245.      Out[2] := -Graphics3D-
  246.  
  247.      In[3] := Geomview[%3, DisplayHost->"riemann"] This displays the
  248. graphics `%3' on the remote host named `riemann'.
  249.  
  250. `Geomview' recognizes the string `"local"' as a value for
  251. `$DisplayHost'; it forces the graphics to be displayed on the local
  252. machine.
  253.  
  254. In addition to knowing the name of the machine you want to run Geomview
  255. on, the `Geomview' needs to know the type of that machine (SGI or NeXT).
  256. By default, `Geomview' assumes that it is the same kind of computer as
  257. the one you are running Mathematica on.  The `MachType' option lets you
  258. explicitly specify the type of the `DisplayHost' computer; it should be
  259. one of the strings `"sgi"' or `"next"'.
  260.  
  261. You can use `SetOptions' to change the default `DisplayHost'
  262. and `MachType'.  For example,
  263.      In[4] := SetOptions[Geomview, DisplayHost->"riemann",
  264. MachType->"sgi"] arranges for `Geomview' to run Geomview on an SGI
  265. workstation named `riemann'.
  266.  
  267.  
  268. Transporting Mathematica Files to Geomview by Hand
  269. --------------------------------------------------
  270.  
  271. The auxilliary function `WriteChunk' is for those who can only use
  272. Mathematica on a non-Unix machine (Mac, PC) or a Unix machine that is
  273. not on a network with an SGI or NeXT.  `WriteChunk[FILE, GRAPHICS]'
  274. generates a file named FILE which contains the graphics object GRAPHICS
  275. in the format accepted by `math2oogl'.
  276.  
  277. You can transfer that file to a computer that has Geomview installed on
  278. it and then use the programs `math2oogl', `oogl2rib', and
  279. `geomview' directly from the shell.  These programs are distributed
  280. in the `bin/sgi' (on SGIs) or `bin/next' (on NeXTs)
  281. subdirectory of the Geomview directory, and may have been installed so
  282. that they are on your `path'. 
  283.  
  284.      In[1]:= <<OOGL.m
  285.  
  286.      In[2]:= Plot3D[ Sin[x + Sin[y]], {x,-2,2}, {y,-2,2} ]
  287.  
  288.      Out[2]= -SurfaceGraphics-
  289.  
  290.      In[3]:= WriteChunk["mychunk",%2]
  291. This writes the file `mychunk' which contains a description
  292. of the graphics object.  You can then transfer this file to an SGI or
  293. NeXT and type
  294.      math2oogl < mychunk > mma.oogl
  295. to convert it to the OOGL file `mma.oogl' which you can then view
  296. using Geomview. This is the equivalent of the `WriteOOGL' command. 
  297.  
  298. For a result equivalent to the `Geomview' or `Show'
  299. commands, type
  300.      math2oogl -togeomview Mathematica geomview < mychunk
  301.  
  302. The `WriteRIB' command can be emulated from the shell as
  303.      math2oogl < mychunk | oogl2rib -n mma.tiff
  304.  
  305.  
  306.  
  307.  
  308.  
  309. Details of the Mathematica->Geomview Package
  310. ============================================
  311.  
  312. The `OOGL.m' package uses the external program `math2oogl' to
  313. convert `Graphics3D' objects to OOGL format, because a compiled
  314. external program is able to do this conversion many times faster than
  315. Mathematica.
  316.  
  317. The converter will sometimes handle colored SurfaceGraphics objects
  318. correctly that Mathematica does not handle correctly, which means that
  319. Geomview[object] sometimes works where Show[object] will give errors.
  320.  
  321. The converter supports the `Polygon', `Line', and `Point'
  322. graphics primitives, `RGBColor Graphics3D' directives, and
  323. `SurfaceGraphics' objects with or without `RGBColor'
  324. directives, and lists of any combination of these. It silently ignores
  325. all other directives.
  326.  
  327. The Mathematica to RenderMan conversion is actually a two-step process:
  328. Mathematica->OOGL (math2oogl), and OOGL->RenderMan (oogl2rib). The
  329. math2oogl program has only been tested on SGIs and NeXTs, but could
  330. theoretically compile on any machine. The oogl2rib program depends on
  331. the OOGL (Object Oriented Graphics Language) libraries, which now only
  332. exist on SGI and NeXT machines.
  333.  
  334. In the `WriteOOGL' and `WriteRIB' commands, filename can either be a
  335. string containing a filename, an `OutputStream' object, or a string
  336. starting with a `!' to send the output to a command.  Object can be a
  337. `Graphics3D' object, a `SurfaceGraphics' object, or a list of these.
  338.  
  339. The packages work best with Mathematica 2.0 or better.  With version 1.2,
  340. the Geomview display is always on the local host. 
  341.  
  342.  
  343. Installing the Mathematica Packages
  344. ===================================
  345.  
  346. If Geomview is properly installed on your system according to the
  347. instructions in *Note Installation::, then the Mathematica-to-Geomview
  348. packages should work as described here; there should be no need for
  349. additional installation procedures.  In practice, however, it is
  350. sometimes necessary to taylor the installation of the Mathematica
  351. packages and/or of Geomview itself to suit the needs of a particular
  352. system.  This section contains details about how the installation works;
  353. if the Mathematica-to-Geomview connection does not seem to work for you
  354. after following the Geomview installation procedure, consult this
  355. section to see what might need to be fixed.
  356.  
  357. In this section, the phrase *Geomview installation* refers any of
  358. the procedures in *Note Installation::.  The way the Mathematica packages
  359. work and are installed is the same regardless of whether you have
  360. one of the binary distributions or the source distribution.
  361.  
  362.  
  363.   1. The relevant mathematica files are `OOGL.m', `Geomview.m', and
  364.      `BezierPlot.m'; Mathematica must be able to find these files.  They
  365.      are distributed in the `$GEOMROOT/mathematica' subdirectory of the
  366.      binary distributions, and in the
  367.      `$GEOMROOT/src/bin/geomutil/math2oogl' subdirectory of the source
  368.      distribution.  These files need to be in a directory that is on
  369.      Mathematica's search path.  You can look at the value of the
  370.      `$Path' variable in a Mathematica session on your system to see a
  371.      list of the directories on Mathematica's search path.
  372.  
  373.      The Geomview installation procedure puts copies of the Mathematica
  374.      packages into a directory that you specify (`MMAPACKAGEDIR').  This
  375.      should ensure that Mathematica can find them.  Alternately, you could
  376.      arrange to append the pathname of the Mathmematica package subdirectory
  377.      of the Geomview distribution to the `$Path' variable each time you
  378.      run Mathematica.
  379.  
  380.   2. The package `OOGL.m' needs to be able to invoke the programs
  381.      `geomview', `math2oogl', and `oogl2rib'.  The Geomview
  382.      installation procedure installs these programs into a directory that you
  383.      specify for executables (`BINDIR').  Ideally, this directory should
  384.      be on your shell's `$path'.  More specifically, it should be on
  385.      the `$path' of the shell in which Mathematica runs; the directory
  386.      `/usr/local/bin' is usually a good choice.  You can see the list of
  387.      directories on this path by giving the command `!echo $path' in
  388.      Mathematica.
  389.  
  390.      If for some reason you can't arrange for `geomview',
  391.      `math2oogl', and `oogl2rib' to be in a directory on the
  392.      shell's `$path', you can modify `OOGL.m' to cause it to look
  393.      for them using absolute pathnames.  To do this, change the definitions
  394.      of the variables `$GeomviewPath' and `$GeomRoot', which are
  395.      defined near the top of the file.  Change `$GeomviewPath' to the
  396.      absolute pathname of the `geomview' shell script on your system.
  397.      Change `$GeomRoot' to the absolute pathname of the
  398.      `$GEOMROOT' directory on your system.  If you do this, you should
  399.      also make sure there are copies of `geomview', `math2oogl',
  400.      and `oogl2rib' in the `$GEOMROOT/bin/sgi' (on an SGI) or
  401.      `$GEOMROOT/bin/next' (on a NeXT) directory.
  402.  
  403.   3. The `geomview' shell script, which `OOGL.m' uses to invoke
  404.      Geomview, needs to be able to find the geomview executable file (which
  405.      is called `gvx' on the SGI and `Geomview.app/Geomview' on the
  406.      NeXT).  The Geomview installation procedure should have been taken care
  407.      of this, but if your Mathematica session doesn't seem to be able to
  408.      invoke Geomview, it's worth double-checking that the settings in the
  409.      `geomview' script are correct.
  410.  
  411.  
  412.